<template>
  <div class="headerItem">
    <el-input placeholder="请输入商户全称搜索" style="width: 250px" />
    <el-button :icon="Plus" link style="color: rgb(18, 150, 219)" @click="add">新增</el-button>
  </div>
  <div class="tableBox">
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="id" label="商户编号" width="180" align="center" />
      <el-table-column prop="name" label="商户信息" width="580" align="left">
        <template #default="scope">
          <div class="infoBox">
            <p><span class="infoLabel">商户全称：</span>{{ scope.row.fullName }}</p>
            <p><span class="infoLabel">商户简称：</span>{{ scope.row.shortName }}</p>
            <p><span class="infoLabel">创建人：</span>{{ scope.row.creator }}</p>
            <p><span class="infoLabel">创建时间：</span>{{ scope.row.createTime }}</p></div
          >
        </template>
      </el-table-column>
      <el-table-column prop="action" label="操作" align="center">
        <template #default="scope">
          <div class="actionBox"
            ><h3>商户资料</h3>
            <el-button type="primary" size="large" @click="formComRef.onOpen(scope.row)"
              >编辑</el-button
            >
            <el-button size="large" type="primary" @click="() => {}">重置密码</el-button>
            <el-button size="large" type="primary">原始密码</el-button>
            <el-button size="large" type="primary" @click="() => {}">商户证照</el-button>
            <el-button size="large" type="primary" @click="() => {}"
              ><el-icon><CaretBottom /></el-icon>展开</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pagination"
      @change="changePagination"
      background
      layout="->,prev, pager, next"
      :total="total"
    />
  </div>
  <FormCom ref="formComRef" @success="getList" />
  <el-dialog v-model="passwordDialog" title="原始密码" width="500">
    <el-input v-modal="password" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisible = false"> Confirm </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { Plus, CaretBottom } from '@element-plus/icons-vue'
import * as merchantApi from '@/api/merchant/index'
import FormCom from './components/formCom.vue'
const tableData = ref([])
const formComRef = ref(null)
const pageData = ref({
  pageSize: 10,
  pageNo: 1
})
const password = ref('')
const passwordDialog = ref(false)
const total = ref(0)
onMounted(() => {
  getList()
})
const getList = async () => {
  merchantApi.getMerchantList(pageData.value).then((res) => {
    tableData.value = res.list
    total.value = res.total
  })
}
const add = () => {
  formComRef.value.onOpen({})
}
const changePagination = (page, size) => {
  pageData.value.pageNo = page
  pageData.value.pageSize = size
  getList()
}
const lastPassword = (password) => {
  console.log('password', password)
  passwordDialog.value = true
  password.value = password
}
</script>
<style lang="scss" scoped>
.headerItem {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}
.infoBox {
  line-height: 40px;
  font-size: 14px;
  .infoLabel {
    font-weight: 600;
  }
}
.tableBox {
  padding: 20px 0;
  border-radius: 10px;
  background: #fff !important;
  .pagination {
    margin: 20px 0;
  }
}
.actionBox {
  display: flex;
  align-items: center;
  h3 {
    margin-right: 20px;
    color: #1890ff;
  }
}
</style>
